import React from 'react';

import SearchTable from '@/components/common/SearchTable';
import { connect } from 'dva';

@connect((state: any) => ({
  vehicleInfo: state.vehicleInfo,
  loading: state.loading.effects['vehicleInfo/getFetchPage'],
}))
export default class ChangeTab extends React.Component<any, any> {
  a1 = 0;
  a2 = 0;
  onSource = (page, size, args) =>
    new Promise(async resolve => {
      const { vehicleInfo } = this.props;

      const res = await this.props.dispatch({
        type: 'vehicleInfo/getFetchPage',
        payload: {
          url: '/simcard/realnamerecordpage',
          vin: vehicleInfo.vin,
          current: page,
          pageSize: size,
          ...args,
        },
      });
      if (res && res.statusCode === '0') {
        resolve({
          total: res.data.pagination.total,
          data: res.data.list,
        });
      } else {
        resolve({
          total: 0,
          data: [],
        });
      }
    });

  render() {
    const {
      vehicleInfo: {
        pageData: { pagination },
      },
    } = this.props;

    const columns = [
      {
        title: '序号',
        dataIndex: 'index',
        render: (text: any, record: any, index: any) => {
          return index + 1 + (pagination.current - 1) * pagination.pageSize;
        },
      },
      {
        title: '实名操作时间',
        dataIndex: 'createTime',
      },
      {
        title: '实名类型',
        dataIndex: 'businessType',
        render: (text: any) => {
          return text === 0 ? '开户' : text === 1 ? '过户' : text === 3 ? '换件入网' : '';
        },
      },
      {
        title: '入网类型',
        dataIndex: 'type',
        render: (text: any) => {
          return text === 1
            ? '个人'
            : text === 2
              ? '个人委托'
              : text === 3
                ? '单位'
                : text === 4
                  ? '车厂'
                  : '';
        },
      },
      {
        title: '执行结果',
        dataIndex: 'executeResult',
        render: (text: any) => {
          return text === 1 ? '成功' : text === 2 ? '失败' : '';
        },
      },
    ];
    return (
      <>
        <SearchTable
          tableProps={{
            scroll: { x: true },
            columns: columns,
            onSource: this.onSource,
          }}
        />
      </>
    );
  }
}
